let check = document.getElementById("check")
let checkStart = document.getElementById("checkStart")
let container = document.getElementById("container")
let weather = document.getElementById("weather")
let winddirection = document.getElementById("winddirection")
let temperature = document.getElementById("temperature")
let citys = document.getElementById("city")
let cloud = document.getElementsByClassName("cloud")
checkStart.onclick = function () {
    let city = check.value
    if (city == "") {
        alert("请输入一个城市")
    }
    let xhr = new XMLHttpRequest()
    xhr.onreadystatechange = function () {
        if (xhr.readyState == 4 && xhr.status == 200) {
           try{
            let xhr2 = JSON.parse(xhr.responseText)
            citys.innerHTML = "城市：" + xhr2.lives[0].city
            weather.innerHTML = "天气：" + xhr2.lives[0].weather
            temperature.innerHTML = "温度：" + xhr2.lives[0].temperature + "度"
            winddirection.innerHTML = "风向：" + xhr2.lives[0].winddirection
            cloud[0].style.display = "block"
           }catch{
           alert("请输入中国的省，市，自治区，特别行政区")
           }
            
        }
        }
        
    
    xhr.open("GET", "https://restapi.amap.com/v3/weather/weatherInfo?city=" + city + "&key=d192c1611950fd0173694d4121f1fee9", true)
    xhr.send()
}